#include<bits/stdc++.h>
using namespace std;
const int N = 3e5+10;
#define int long long
int up[N],down[N];
int val[N];
struct segment_tree{
    int ma[N<<2];
    void push_up(int now){
        ma[now] = max(ma[now<<1],ma[now<<1|1]);   
    }
    void build(int now,int l,int r){
        if(l == r){
            ma[now] = 0;
            return;
        }
        int mid = (l + r)/2;
        build(now<<1,l,mid);
        build(now<<1|1,mid+1,r);
        push_up(now);
    }
    void update(int now,int l,int r,int p,int v){
        if(l == r){
            ma[now] = v;
            return;
        }
        int mid = (l + r)/2;
        if(p <= mid){
            update(now<<1,l,mid,p,v);
        }else{
            update(now<<1|1,mid+1,r,p,v);
        }
        push_up(now);
    }
    int query(int now,int l,int r,int x,int y){
        if(x <= l && r <= y){
            return ma[now];
        }
        int res = 0;
        int mid = (l + r)/2;
        if(x <= mid){
            res = max(res,query(now<<1,l,mid,x,y));
        }
        if(mid < y){
            res = max(res,query(now<<1|1,mid+1,r,x,y));
        }
        return res;
    }
}sg;
struct segment_tree1{
    int ls[N*20],rs[N*20];
    int sum[N*20];
    int pcnt;
    void update(int &now,int l,int r,int p,int v){
        if(!now){
            now = ++pcnt;
            return;
        }
        sum[now] += v;
        if(l == r){
            return;
        }
        int mid = (l + r)/2;
        if(p <= mid){
            update(ls[now],l,mid,p,v);
        }else{
            update(rs[now],mid+1,r,p,v);
        }
    }
    int query(int now,int l,int r,int x,int y){
        if(x <= l && r <= y){
            return sum[now];
        }
        int mid = (l + r)/2;
        int res = 0;
        if(x <= mid){
            res += query(ls[now],l,mid,x,y);
        }
        if(mid < y){
            res += query(rs[now],mid+1,r,x,y);
        }
        return res;
    }
}sg1;
int rots[N];
int xnums[N*3],xcnt;
int ynums[N*3],ycnt;
struct Point{
    int x,y;
}ps[N];
vector<int> lines[N];
bool cmp1(int x,int y){
    return ps[x].x < ps[y].x;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    freopen("altar.in","r",stdin);
    freopen("altar.out","w",stdout);
    int n,q;
    cin>>n>>q;
    for(int i = 1;i<=n;i++){
        int x,y;
        cin>>x>>y;
        ps[i].x = x;
        ps[i].y = y;
        xnums[++xcnt] = x;
        ynums[++ycnt] = y;
    }
    sort(xnums + 1,xnums + 1 + xcnt);
    sort(ynums + 1,ynums + 1 + ycnt);
    xcnt = unique(xnums + 1,xnums + 1 + xcnt) - xnums - 1;
    ycnt = unique(ynums + 1,ynums + 1 + ycnt) - ynums - 1;
    for(int i = 1;i<=n;i++){
        ps[i].x = lower_bound(xnums + 1,xnums + 1 + xcnt,ps[i].x) - xnums;
        ps[i].y = lower_bound(ynums + 1,ynums + 1 + ycnt,ps[i].y) - ynums;
        lines[ps[i].y].push_back(i);
        down[ps[i].x]++;
    }
    for(int i = 1;i<=xcnt;i++){
        sg1.update(rots[0],1,xcnt,i,1);
    }
    sg.build(1,1,xcnt);
    int ama = 0;
    int acnt = 0;
    for(int i = 1;i<=ycnt;i++){
        sort(lines[i].begin(),lines[i].end(),cmp1);
        for(int v : lines[i]){
            up[v]++;
            down[v]--;
            int nv = min(up[v],down[v]);
            sg.update(1,1,xcnt,ps[v].x,nv);
            if(q == 2){
                if(nv > val[v]){
                    for(int j = val[v] + 1;j <= nv;j++){
                        sg1.update(rots[j],1,xcnt,ps[v].x,1);
                    }
                }
                if(nv < val[v]){
                    for(int j = val[v];j > nv;j--){
                        sg1.update(rots[j],1,xcnt,ps[v].x,-1);
                    }
                }
            }
            val[v] = nv;
        }
        for(int j = 1;j < lines[i].size();j++){
            if(ps[lines[i][j]].x - ps[lines[i][j - 1]].x <= 1){
                continue;
            }
            int rs = min(min(j,(int)lines[i].size() - j),sg.query(1,1,xcnt,ps[lines[i][j - 1]].x + 1,ps[lines[i][j]].x - 1));
            if(q == 1){
                ama = max(rs,ama);
            }else{
                if(rs >= ama){
                    int cnt = sg1.query(rots[rs],1,xcnt,ps[lines[i][j - 1]].x + 1,ps[lines[i][j]].x - 1);
                    if(rs == ama){
                        acnt += cnt;
                    }else{
                        ama = rs;
                        acnt =  cnt;
                    }
                }
            }
        }
    }
    if(q == 1){
        cout<<ama<<'\n';
    }else{
        if(ama != 0){
            cout<<acnt<<'\n';
        }else{
            cout<<0<<'\n';
        }
    }
}
// why not build big example